package wsz.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import wsz.dao.JdbcDao;
import wsz.factory.CommonFactoryBean;

import javax.annotation.PostConstruct;

/**
 * 注解启动类的参数类
 * 1.定义配置注解
 * 2.注解扫描包
 * 3.配置读取
 * 4. @Bean 自定义bean对象
 * @author wsz
 * @date 2021/10/14 17:17
 **/
@Configuration
@ComponentScan(value = {"wsz.dao"})
@PropertySource(value = "classpath:jdbc.properties")
public class SpringConfig {

    @Value(value ="${name}")
    private String name;

    @PostConstruct
    public void init() {
        System.out.println("name="+name);
    }

    @Bean
    public JdbcDao jdbcDao() {
        JdbcDao jdbcDao = new JdbcDao();
        jdbcDao.setName(name);
        return jdbcDao;
    }

    @Bean(value = "commonFactoryBean")
    public CommonFactoryBean factoryBean() {
        CommonFactoryBean bean = new CommonFactoryBean();

        bean.setName("factoryBean getObject");
        return bean;
    }

}
